﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //登录
        protected void Unnamed3_Click(object sender, EventArgs e)
        {
            var uid = tbUsername.Text.Trim();
            var pwd = tbPassword.Text.Trim();

            var sql = string.Format("select * from Users where Username='{0}'", uid);
            var dt = DbHelper.GetData(sql);

            if (dt.Rows.Count==1)
            {
                var item = dt.Rows[0];

                var isActived = (bool)item.ItemArray[3];
                var isDelete = (bool)item.ItemArray[4];
                var password = item.ItemArray[2].ToString();
                if (isDelete)
                {
                    Response.Write("账号已被删除");
                }
                else
                {
                    if (isActived)
                    {
                        if (password==pwd)
                        {
                            Response.Write("登录成功!");
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Response.Write("密码错误");
                        }
                    }
                    else
                    {
                        Response.Write("账号已过期或被冻结");
                    }
                }
            }
        }
    }
}